<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--  没有作用 这段javascript 原因 没有写在 预加载函数中 $(function(){})  --%>
<script type="text/javascript">
    $(function () {
        $("#submit_btn").click(function () {
            var index = $("#pn_input").val();
            var url = "${list.url}";
            window.location.href = url + index;
        });
    });
</script>
<div id="page_nav">
    <a href="${list.url}1">首页</a>
    <c:if test="${list.hasPrev}">
        <a href="${list.url}${list.currentPage - 1}">上一页</a>
    </c:if>

    <%-- 设置begin 的索引 设置 end 的索引 1 索引小于3 --%>
    <c:if test="${list.totalPage <= 5}">
        <c:set var="startIndex" value="1" scope="page"></c:set>
        <c:set var="endIndex" value="${list.totalPage}" scope="page"></c:set>
    </c:if>
    <%-- 第二种情况 totalPage 大于 5 --%>
    <c:if test="${list.totalPage > 5}">
        <%-- 当前页第一种情况 --%>
        <c:if test="${list.currentPage <= 3}">
            <c:set var="startIndex" value="1" scope="page"></c:set>
            <c:set var="endIndex" value="5" scope="page"></c:set>
            <%--<c:set var="startIndex" value="${list.currentPage - 2}" scope="page"></c:set>
            <c:set var="endIndex" value="${list.currentPage + 2}" scope="page"></c:set>--%>
        </c:if>
        <c:if test="${list.currentPage >= 3}">
            <c:set var="startIndex" value="${list.currentPage - 2}" scope="page"></c:set>
            <c:set var="endIndex" value="${list.currentPage + 2}" scope="page"></c:set>
        </c:if>
        <c:if test="${list.currentPage + 2 > list.totalPage}">
            <c:set var="startIndex" value="${list.totalPage-4}" scope="page"></c:set>
            <c:set var="endIndex" value="${list.totalPage}" scope="page"></c:set>
        </c:if>
    </c:if>
    <c:forEach begin="${startIndex}" end="${endIndex}" step="1" var="index">
        <c:if test="${index == list.currentPage}">
            <span style="color:blue">【${list.currentPage}】</span>
        </c:if>
        <c:if test="${index != list.currentPage}">
            <a href="${list.url}${index}">${index}</a>
        </c:if>
    </c:forEach>

    <c:if test="${list.hasNext}">
        <a href="${list.url}${list.currentPage + 1}">下一页</a>
    </c:if>

    <a href="${list.url}${list.totalPage}">末页</a>
    共${list.totalPage}页，${list.totalCount}条记录 到第<input value="${list.currentPage}" name="current_page" id="pn_input"/>页
    <input id="submit_btn" type="button" value="确定">
</div>